package sourceagile.client;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

/**
 * Client feature to test the connection with the web server.
 * 
 * 
 * @Architecture
 */
public class SaveLiveFeed {

	public static void main(String[] args) {

		String location = "http://datastore.projectnection.appspot.com/SaveDataService?kind=LiveFeed"
				+ "&fieldsKind=Entity&fieldsName=entityIDTo&fieldsValue=AllineO"
				+ "&fieldsKind=Entity&fieldsName=entityIDFrom&fieldsValue=LiveSource"
				+ "&fieldsKind=String&fieldsName=liveFeedDescription&fieldsValue=@AllineO"
				+ "isnowconnectedto@LiveSource"
				+ "&fieldsKind=Date&fieldsName=liveFeedDate&fieldsValue=170000000";

		try {

			String message = URLEncoder.encode("my message", "UTF-8");
			URL url = new URL(location);
			HttpURLConnection connection = (HttpURLConnection) url
					.openConnection();
			connection.setDoOutput(true);
			connection.setRequestMethod("POST");

			OutputStreamWriter writer = new OutputStreamWriter(
					connection.getOutputStream());
			writer.write("message=" + message);
			writer.close();

			if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
				System.out.println(connection.getOutputStream());
			} else {
				System.out.println(connection.getResponseCode());
			}

		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();

		} catch (MalformedURLException e) {
			e.printStackTrace();

		} catch (IOException eio) {

			eio.printStackTrace();
		}
	}

}
